import Vue from 'vue'
import Vuex from 'vuex'
// #ifdef APP-PLUS
import {
	notificationTexts
} from "@/uni_modules/tq-gt-notice";
// #endif
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {
			// headPhoto:'/static/images/headphotos/2178f6f50d5f827cea8d947a9b73df49.png',
			nickname:'',
			accountNum:'',
			name:'',
			gender:'',
			registerTime:''
		},
		accountNum:'',
		hasSetExper: false
	},
	mutations:{
		login(state,provider){
			state.hasLogin = true;
			state.accountNum = provider.accountNum;
			state.userInfo = provider;
			uni.setStorage({
				key: 'messageStore',
				data: JSON.stringify(state),
				success: function () {
					console.log('登录信息储存成功');
				}
			});
			    // #ifdef APP-PLUS
			    notificationTexts({
			      title: "登录成功",
			      texts: [
			        `用户：${provider.nickname}`
			      ],
			      cancel: true,
			      lockShow: true,
			      url: ``
			    });
			    // #endif
		},
		updateAccountNum(state, provider) {
			state.accountNum = provider;
			uni.setStorage({
				key: 'messageStore',
				data: JSON.stringify(state),
				success: function () {
					console.log('登录信息储存成功');
				}
			});
		},
		updateUserInfo(state,provider){
			state.userInfo = provider;
			//缓存用户信息
			uni.setStorage({
				key: 'userInfo',  
				data: provider
			});
			uni.setStorage({
				key: 'messageStore',
				data: JSON.stringify(state),
				success: function () {
					console.log('登录信息储存成功');
				}
			});
		},
		logout(state) {
			state.hasLogin = false;
			state.accountNum = '';
			state.userInfo = {
				// headPhoto:'/static/images/headphotos/missing-face.png',
				nickname:'',
				accountNum:'',
				name:'',
				gender:'',
				registerTime:''
			};
			uni.removeStorage({  
				key: 'userInfo'  
			});
			uni.setStorage({
				key: 'messageStore',
				data: JSON.stringify(state),
				success: function () {
					console.log('登录信息储存成功');
				}
			});
		},
		isSetExper(state){
			state.hasSetExper = true;
			uni.setStorage({
				key: 'messageStore',
				data: JSON.stringify(state),
				success: function () {
					console.log('登录信息储存成功');
				}
			});
		},
		logoutExper(state){
			state.hasSetExper = false;
			uni.setStorage({
				key: 'messageStore',
				data: JSON.stringify(state),
				success: function () {
					console.log('登录信息储存成功');
				}
			});
		},
		linkequip(state,provider){
			uni.setStorage({
				key: 'linkequip',  
				data: provider
			});
		},
		closelinkequip(state){
			uni.removeStorage({
				key: 'linkequip'  
			});
		}
	},
	
	actions:{
		
	}
})
export default store